﻿/*
===========================================================================
Immemorsion LGPL Source code
Copyright trszdev - rahimyanov@gmail.com

This file is part of Immemorsion.

Immemorsion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Immemorsion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Immemorsion.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
using System;
using System.Runtime.InteropServices;

namespace Immemorsion.PlatformApi
{

    /// <summary>
    /// "Static class which provides WinApi calls"
    /// </summary>
    public static class WindowsApi
    {

        [DllImport("kernel32.dll")]
        public static extern void GetSystemInfo(out WindowsSystemInfo lpSystemInfo);

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 processId);

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern Int32 CloseHandle(IntPtr handle);

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern Int32 ReadProcessMemory
            (
            IntPtr processHandle,
            IntPtr baseAddress,
            [In, Out] byte[] buffer,
            UInt32 size,
            out IntPtr numberOfBytesRead
            );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern int VirtualQueryEx
            (
            IntPtr processHandle,
            IntPtr baseAddress,
            out WindowsMemoryBasicInformation buffer,
            uint dwLength
            );

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern bool WriteProcessMemory(IntPtr processHandle, IntPtr baseAddress,
          byte[] buffer, int bufferSize, ref int numberOfBytesWritten);

    }
}
